package com.example.myapplication22;

import androidx.appcompat.app.AppCompatActivity;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

public class MainActivity extends AppCompatActivity implements View.OnClickListener {
    Button b1;//登录
    Button b2;//注册
    EditText userid;
    EditText userpsd;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        b1=(Button) findViewById(R.id.button1);
        b2=(Button) findViewById(R.id.button2);
        b1.setOnClickListener(this);
        b2.setOnClickListener(this);
        userid = findViewById(R.id.text_userid);
        userpsd = findViewById(R.id.text_userpsd);
    }
    @Override
    public void onClick(View v) {
        if (v.getId()==R.id.button1){
            // TODO Auto-generated method stub
            String name = userid.getText().toString();
            String psd = userpsd.getText().toString();
            if("123456".equals(name)&&"123456".equals(psd)){
                  Intent intent = new Intent();
                  intent.setClass(MainActivity.this, LoginActivity.class);//this前面为当前activty名称，class前面为要跳转到得activity名称
                  intent.putExtra("username",name);//记录当前用户名
                  startActivity(intent);
            }else{
                Toast.makeText(this, "用户名或密码不正确！", Toast.LENGTH_SHORT).show();
            }

        }
        else if(v.getId()==R.id.button2){
            b2.setVisibility(v.VISIBLE);
        }
    }

}